package com.yunji.news.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunji.news.entity.School;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 院校Mapper接口
 *
 * @author yunji
 * @since 2024-11-23
 */
@Mapper
public interface SchoolMapper extends BaseMapper<School> {
    
    /**
     * 获取院校Logo列表（用于首页展示）
     */
    @Select("SELECT id, name, short_name, logo_url, website_url FROM schools " +
            "WHERE status = 1 AND deleted = 0 ORDER BY sort_order ASC, id ASC")
    List<School> selectSchoolLogos();
    
    /**
     * 分页查询院校列表（支持关键字搜索）
     */
    @Select("<script>" +
            "SELECT * FROM schools WHERE deleted = 0 " +
            "<if test='keyword != null and keyword != \"\"'>" +
            "AND (name LIKE CONCAT('%', #{keyword}, '%') " +
            "OR short_name LIKE CONCAT('%', #{keyword}, '%') " +
            "OR city LIKE CONCAT('%', #{keyword}, '%'))" +
            "</if>" +
            "<if test='city != null and city != \"\"'>" +
            "AND city = #{city}" +
            "</if>" +
            "<if test='schoolType != null and schoolType != \"\"'>" +
            "AND school_type = #{schoolType}" +
            "</if>" +
            "ORDER BY sort_order ASC, id DESC" +
            "</script>")
    IPage<School> selectSchoolPage(Page<School> page, 
                                   @Param("keyword") String keyword,
                                   @Param("city") String city,
                                   @Param("schoolType") String schoolType);
}